package com.jy.adscm.operation.hscrb.controller;


import com.jy.adscm.operation.hscrb.bean.HcConsumables;
import com.jy.adscm.operation.hscrb.service.HcConsumablesService;
import com.jy.adscm.operation.hscrb.service.HcConsumablesdetailService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yyy
 * @since 2018-11-29
 */
@Controller
@RequestMapping("/hcConsumables")
public class HcConsumablesController {
    @Autowired
    HcConsumablesService hcConsumablesService;
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    HcConsumablesdetailService hcConsumablesdetailService;

    SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @RequestMapping("insert")
    public SimpleCoreResponse insert(HcConsumables hcConsumables, HttpServletRequest request){
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        String taskCode=sd.format(new Date()).replaceAll("-","").replaceAll(":","");
        hcConsumables.setTaskcode(Long.valueOf(taskCode));//根据日期时间生成流水号
        hcConsumables.setTaskreleaseperson(token.getUser().getId().toString());
        hcConsumables.setTaskreleaseaddtime(new Date());
        return  new SimpleCoreResponse("200","新增成功",hcConsumablesService.insert(hcConsumables));
    }
}

